Fix `harness = false` on `[lib]` sections
authorAlex Crichton <alex@alexcrichton.com>
Mon, 20 Jun 2016 16:28:09 +0000 (09:28 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 21 Jun 2016 15:41:00 +0000 (08:41 -0700)
Now that this is fixed upstream, we can actually add a test for this!

Closes #2305

src/cargo/ops/cargo_rustc/mod.rs
src/rustversion.txt
tests/registry.rs
tests/rustc.rs
tests/test.rs

index 6b07d8f413f0bac2696c0af6e9a9a7d968b0beb0..ab0b829626a559f0c1c708059e1769deb1b1049a 100644 (file)
@@ -467,8 +467,10 @@ fn build_base_args(cx: &Context,
 
     cmd.arg("--crate-name").arg(&unit.target.crate_name());
 
-    for crate_type in crate_types.iter() {
-        cmd.arg("--crate-type").arg(crate_type);
+    if !test {
+        for crate_type in crate_types.iter() {
+            cmd.arg("--crate-type").arg(crate_type);
+        }
     }
 
     let prefer_dynamic = (unit.target.for_host() &&
@@ -515,6 +517,8 @@ fn build_base_args(cx: &Context,
 
     if test && unit.target.harness() {
         cmd.arg("--test");
+    } else if test {
+        cmd.arg("--cfg").arg("test");
     }
 
     if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
index 1557cfb2fe4eadd94725fed161797246db069135..0594aef9b997816ec173730ea589b6c0a8809046 100644 (file)
@@ -1 +1 @@
-2016-05-13
+2016-06-21
index 83ddb6b7427860e92572ad35bd27fb32285c2f9b..7f600fb17862a3abc83921fcc817632380ed577c 100644 (file)
@@ -1067,6 +1067,6 @@ fn upstream_warnings_on_extra_verbose() {
 
     assert_that(p.cargo("build").arg("-vv"),
                 execs().with_status(0).with_stderr_contains("\
-[..] warning: function is never used[..]
+[..]warning: function is never used[..]
 "));
 }
index e65d713d41f90e83a40055b1e2afe1ca94da5eb9..7281bea66a45c1b72e1fd511a39205565d00f7d0 100644 (file)
@@ -209,7 +209,7 @@ fn build_with_args_to_one_of_multiple_tests() {
 [COMPILING] foo v0.0.1 ({url})
 [RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
         --out-dir {dir}{sep}target{sep}debug [..]`
-[RUNNING] `rustc tests{sep}bar.rs --crate-name bar --crate-type bin -g \
+[RUNNING] `rustc tests{sep}bar.rs --crate-name bar -g \
         -C debug-assertions [..]--test[..]`
 ", sep = SEP,
                 dir = p.root().display(), url = p.url())));
index 11a2cc54c9fb321463fbf6e905ac40a71dc9cf2d..78b9a9e7125d5ae42626e7a7da86487676c1a707 100644 (file)
@@ -2161,3 +2161,35 @@ fn test_panic_abort_with_dep() {
     assert_that(p.cargo_process("test").arg("-v"),
                 execs().with_status(0));
 }
+
+#[test]
+fn cfg_test_even_with_no_harness() {
+    if !is_nightly() {
+        return
+    }
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            harness = false
+            doctest = false
+        "#)
+        .file("src/lib.rs", r#"
+            #[cfg(test)]
+            fn main() {
+                println!("hello!");
+            }
+        "#);
+    assert_that(p.cargo_process("test").arg("-v"),
+                execs().with_status(0)
+                       .with_stdout("hello!\n")
+                       .with_stderr("\
+[COMPILING] foo v0.0.1 ([..])
+[RUNNING] `rustc [..]`
+[RUNNING] `[..]`
+"));
+}